<form name="frmBlog" class="form-horizontal" ng-init="dvm.init()" ng-submit="dvm.publish(frmBlog.$valid)" novalidate>
  <div class="modal-header">
    <button type="button" class="close" ng-click="dvm.cancel()">&times;</button>
    <h4 class="modal-title">发布博客</h4>
  </div>
  <div class="modal-body">
    <div class="form-group">
      <label class="col-sm-2 control-label">标题：</label>
      <div class="col-sm-10">
        <input type="text" name="title" class="form-control" ng-model="dvm.title" required autofocus
            maxlength="50" ng-class="{'x-invalid': frmBlog.$submitted && frmBlog.title.$invalid}">
        <p class="text-danger" ng-show="frmBlog.$submitted && frmBlog.title.$error.required">标题不能为空</p>
        <p class="text-danger" ng-show="frmBlog.$submitted && dvm.exists.title">标题已存在</p>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">分类：</label>
      <div class="col-sm-10" ng-if="!dvm.created">
        <select class="form-control" name="category" ng-model="dvm.category" required
            ng-options="category.id as category.name for category in dvm.categories"
            ng-class="{'x-invalid': frmBlog.$submitted && frmBlog.category.$invalid}"></select>
        <p class="text-danger" ng-show="frmBlog.$submitted && frmBlog.category.$error.required">分类不能为空</p>
      </div>
      <div class="col-sm-10" ng-if="dvm.created">
        <input type="text" name="categoryName" class="form-control" ng-model="dvm.categoryName" required
            maxlength="20" ng-class="{'x-invalid': frmBlog.$submitted && frmBlog.categoryName.$invalid}">
        <p class="text-danger" ng-show="frmBlog.$submitted && frmBlog.categoryName.$error.required">分类名不能为空</p>
        <p class="text-danger" ng-show="frmBlog.$submitted && dvm.exists.category">分类名已存在</p>
      </div>
    </div>
    <div class="form-group" ng-if="sessionUser.role == 'admin'">
      <div class="col-sm-offset-2 col-sm-10">
        <label class="checkbox-inline">
          <input name="type" type="checkbox" value="true" ng-model="dvm.created">新建分类
        </label>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">标签：</label>
      <div class="col-sm-10">
        <input type="text" name="tags" class="form-control" ng-model="dvm.tags" placeholder="多个标签以,隔开" required
            maxlength="20" ng-class="{'x-invalid': frmBlog.$submitted && frmBlog.tags.$invalid}">
        <p class="text-danger" ng-show="frmBlog.$submitted && frmBlog.tags.$error.required">标签不能为空</p>
      </div>
    </div>
  </div>
  <div class="modal-footer">
    <button type="submit" class="btn btn-default" ng-disabled="frmBlog.$invalid">
      <i class="fa fa-share-alt"></i> 发布</button>
    <button type="button" class="btn btn-default" ng-click="dvm.cancel()">
      <i class="fa fa-times"></i> 取消</button>
  </div>
</form>
